package cn.org.eshow.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 详细商品表
 */
@Entity
@Table(name = "product_item")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ProductItem extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;//详细商品ID

    @Column(name = "add_time")
    private Date addTime = new Date();// 添加时间

    @Column(name = "update_time")
    private Date updateTime = new Date();// 更新时间

    @Column
    private String title;// 详细商品标题(颜色)

    @Column
    private Double price = 0.00;// 价格

    @Column(length = 400)
    private String img;//主图片

    @Column
    private String description;//描述

    @Column
    private Integer state = 1;//状态（1上架，0下架）

    @Column
    private Boolean enabled = Boolean.TRUE;//是否可用

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id")
    private Product product;// 商品ID


    public ProductItem() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        ProductItem pojo = (ProductItem) o;
        if (id != null ? !id.equals(pojo.id) : pojo.id != null)
            return false;
        if (addTime != null ? !addTime.equals(pojo.addTime) : pojo.addTime != null)
            return false;
        if (updateTime != null ? !updateTime.equals(pojo.updateTime) : pojo.updateTime != null)
            return false;
        if (title != null ? !title.equals(pojo.title) : pojo.title != null)
            return false;
        if (price != null ? !price.equals(pojo.price) : pojo.price != null)
            return false;
        if (img != null ? !img.equals(pojo.img) : pojo.img != null)
            return false;
        if (state != null ? !state.equals(pojo.state) : pojo.state != null)
            return false;
        if (product != null ? !product.equals(pojo.product) : pojo.product != null)
            return false;
        if (enabled != null ? !enabled.equals(pojo.enabled) : pojo.enabled != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (addTime != null ? addTime.hashCode() : 0);
        result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (img != null ? img.hashCode() : 0);
        result = 31 * result + (state != null ? state.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (product != null ? product.hashCode() : 0);
        result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
        return result;
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", this.id)
                .append("addTime", this.addTime)
                .append("updateTime", this.updateTime)
                .append("title", this.title)
                .append("description", this.description)
                .append("price", this.price)
                .append("img", this.img)
                .append("state", this.state)
                .append("product", this.product)
                .append("enabled", this.enabled)
                .toString();
    }
}
